package com.code.day07.Streamsdy;

import java.util.stream.Stream;

public class DemoStream3 {
    public static void main(String[] args) {
        Stream<Integer> stream = Stream.of(1, 2, 3);
        long res = stream.count(); // 消耗流
        System.out.println(res);
        try {
            stream.forEach(System.out::println); //count消耗流之后流就没了
        } catch (IllegalStateException e) {
            System.out.println("Caught exception!");
            e.printStackTrace(System.out);
        }
        System.out.println("Program finished");
    }

}
